package com.tjbank.cssys.mybatis.impl;


import com.tjbank.cssys.mybatis.IamSequenceDao;
import com.tjbank.cssys.mybatis.entity.IamSequence;
import com.tjbank.cssys.mybatis.entity.IamSequenceKey;
import com.tjbank.cssys.mybatis.mapper.IamSequenceMapper;
import com.tjbank.cssys.mybatis.sqlbuilder.IamSequenceSqlBuilder;
import org.apache.ibatis.exceptions.TooManyResultsException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * IamSequenceDaoImpl
 * 
 * @author PG(Auto Generator)
 * @version V2.0
 */
@Service
public class IamSequenceDaoImpl implements IamSequenceDao {
    @Resource
    private IamSequenceMapper iamSequenceMapper;

    public IamSequenceDaoImpl() {
        super();
    }

    @Override
    public List<IamSequence> selectListBySqlBuilderWithBLOBs(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        return iamSequenceMapper.selectBySqlBuilderWithBLOBs(iamSequenceSqlBuilder);
    }

    @Override
    public List<IamSequence> selectListBySqlBuilder(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        return iamSequenceMapper.selectBySqlBuilder(iamSequenceSqlBuilder);
    }

    @Override
    public IamSequence selectBySqlBuilderWithBLOBs(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        List<IamSequence> listIamSequences = selectListBySqlBuilderWithBLOBs(iamSequenceSqlBuilder);
        if (listIamSequences == null || listIamSequences.isEmpty()) {
            return null;
        } else if (listIamSequences.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamSequences.get(0);
    }

    @Override
    public IamSequence selectBySqlBuilder(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        List<IamSequence> listIamSequences = selectListBySqlBuilder(iamSequenceSqlBuilder);
        if (listIamSequences == null || listIamSequences.isEmpty()) {
            return null;
        } else if (listIamSequences.size() > 1) {
            throw new TooManyResultsException();
        }
        return listIamSequences.get(0);
    }

    @Override
    public IamSequence selectByPrimaryKey(IamSequenceKey iamSequenceKey) throws RuntimeException {
        return iamSequenceMapper.selectByPrimaryKey(iamSequenceKey);
    }

    @Override
    public long countBySqlBuilder(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        return iamSequenceMapper.countBySqlBuilder(iamSequenceSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insert(IamSequence iamSequence) throws RuntimeException {
        return iamSequenceMapper.insert(iamSequence);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int insertUseBatch(List<IamSequence> listIamSequences) throws RuntimeException {
        return iamSequenceMapper.insertUseBatch(listIamSequences);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilder(IamSequence iamSequence, IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        iamSequenceSqlBuilder.setUpdateObject(iamSequence);
        return iamSequenceMapper.updateBySqlBuilder(iamSequenceSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateBySqlBuilderSelective(IamSequence iamSequence, IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        iamSequenceSqlBuilder.setUpdateObject(iamSequence);
        return iamSequenceMapper.updateBySqlBuilderSelective(iamSequenceSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKey(IamSequence iamSequence) throws RuntimeException {
        return iamSequenceMapper.updateByPrimaryKey(iamSequence);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int updateByPrimaryKeySelective(IamSequence iamSequence) throws RuntimeException {
        return iamSequenceMapper.updateByPrimaryKeySelective(iamSequence);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteBySqlBuilder(IamSequenceSqlBuilder iamSequenceSqlBuilder) throws RuntimeException {
        return iamSequenceMapper.deleteBySqlBuilder(iamSequenceSqlBuilder);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = RuntimeException.class)
    public int deleteByPrimaryKey(IamSequenceKey iamSequenceKey) throws RuntimeException {
        return iamSequenceMapper.deleteByPrimaryKey(iamSequenceKey);
    }
}